<?php

function getPage($url, $total, $current) {
    if ($total == 1 || $total == 0) {
        return "";
    }

    if (strpos($url, "?") > 0) {
        $url = $url . "&page=";
    } else {
        $url = $url . "?page=";
    }

    $before = 0;
    $after = 0;
    $showpages = "";
    for ($i = 0; $i < $total; $i++) {
        if ($i == $current) {
            $page = "<span class=red_b><b>" . ($i + 1) . "</b></span>";
        } else {
            if ($i < 5 || $i == ($total - 1) || $i == ($current - 1) || $i == ($current + 1)) {
                $page = "<a href=" . $url . $i . ">" . ($i + 1) . "</a>";
            } else {                
                if ($i < $current) {
                    $before++;
                    if ($before < 4) {
                        $page = ".";
                    } else {
                        $page = "";
                    }
                }

                if ($i > $current) {
                    $after++;
                    if ($after < 4) {
                        $page = ".";
                    } else {
                        $page = "";
                    }
                }
            }
        }
        $showpages = $showpages . " " . $page;
    }
    if ($current != 0) {
        $showpages = "<a href='" . $url . ($current - 1) . "' ><</a>" . " " . $showpages;
    }
    
    if ($current != ($total - 1)) {
        $showpages = $showpages . " " . "<a href='" . $url . ($current + 1) . "' >></a>";
    }
    return $showpages;
}



function getPageSize($total_row, $num_row_of_page) {
    if ($total_row > 0) {
        if ($total_row < $num_row_of_page) {
            $page_count = 1;
        }
        
        if ($total_row % $num_row_of_page) { 
            $page_count = (int) ($total_row / $num_row_of_page) + 1;        
        }else{
            $page_count = $total_row / $num_row_of_page;
        }
    } else {
        $page_count = 0;
    }
    return $page_count;
}

function getPageInfo($total_row, $current_page, $num_row_of_page) {
    $begin = ($current_page * $num_row_of_page) + 1;
    $end = ($current_page + 1) * $num_row_of_page;
    if ($end > $total_row) {
        $end = $total_row;
    }

    $page_info = "<span class=\"red\">" . $total_row . "</span> ����Ϣ����ǰ <span class=\"red\">" . $begin . "-" . $end . "��";
    return $page_info;
}

//echo getPage('change_page.php',10,9);
?>